package com.bingfor.easycablelink.base;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.List;


/**
 * Created by Modificator
 * Date: 15-11-14
 * Time: 下午3:32
 * Connect: yunshangcn@gmail.com
 */
public class ViewPagerFragmentAdapter extends FragmentStatePagerAdapter {
    List<? extends Fragment> fragmentList;
    List<String> title;

    public ViewPagerFragmentAdapter(FragmentManager fm, List<? extends Fragment> fragmentList) {
        super(fm);
        if (fragmentList == null || !(fragmentList.get(0) instanceof Fragment)) {
            throw new IllegalArgumentException("list不能为空,且必须是fragment");
        }
        this.fragmentList = fragmentList;
    }

    public ViewPagerFragmentAdapter(FragmentManager fm, List<? extends Fragment> fragmentList, List<String> title) {
        super(fm);
        this.fragmentList = fragmentList;
        this.title = title;
    }

    @Override
    public Fragment getItem(int position) {

        return fragmentList.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (title == null || title.isEmpty()) return "";
        return title.get(position);
    }

    public void setTitle(List<String> title) {
        this.title = title;
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }
}
